package 笔试;

import java.util.*;

//不太熟悉CPP 用java写的 不知道对不对 如果有错误希望大家纠正
//思路是用dfs
public class 树中abb类型个数 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());
        Map<Integer, List<Integer>> tree = new HashMap<>();
        String ch = sc.nextLine();
        boolean[] visited = new boolean[num];
        for(int i=0;i<num+1;i++){
            int[] nums = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            tree.computeIfAbsent(nums[0],k->new ArrayList<>()).add(nums[1]);
            tree.computeIfAbsent(nums[1],k->new ArrayList<>()).add(nums[0]);
        }
        int res = 0;
        for(int i=1;i<num+1;i++){
            boolean is = dfs(tree,i,1,1,ch);
            if(is){
                res++;
            }
        }
        System.out.println(res);
    }
    public static boolean dfs(Map<Integer, List<Integer>> tree,int last,int level,int node,String ch){
        if(level>3) return false;
        if(level==1){
            for (int i : tree.get(node)) {
                boolean is = dfs(tree,node,level+1,i,ch);
                if(is){
                    return true;
                }
            }
        }
        if(level==2){
            if(ch.charAt(last-1)==ch.charAt(node-1)) return false;
            for (int i : tree.get(node)) {
                boolean is = dfs(tree,node,level+1,i,ch);
                if(is){
                    return true;
                }
            }
        }
        if(level==3){
            if(ch.charAt(node-1)==ch.charAt(last)){
                return true;
            }
        }
        return false;
    }
}